package com.itheima.controller;


import com.itheima.R;
import com.itheima.dto.UserLoginDTO;
import com.itheima.service.IndexService;
import com.itheima.service.SysUserService;
import com.itheima.vo.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/index")
@RequiredArgsConstructor
@Slf4j
public class IndexController {

    private final SysUserService sysUserService;
    private final IndexService indexService;


    /**
     * 登录接口
     * @param userLoginDTO
     * @return
     */
    @PostMapping("/login")
    public R<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO){
        UserLoginVO userLoginVO = sysUserService.login(userLoginDTO);
        //返回去一个令牌
        return R.success(userLoginVO);
    }

    /**
     * 获取用户资料
     * @return
     */
    @PostMapping("/profile")
    public R<?> profile(){
        ProfileVO profile = sysUserService.profile();
        return R.success(profile);
    }

    /**
     * 主页统计信息
     * @return
     */
    @GetMapping("/baseInfo")
    public R baseInfo(){
        BaseInfoVO baseInfoVO = sysUserService.baseInfo();
        return R.success(baseInfoVO);
    }


    /**
     * 获取系统配置
     * @return
     */
    @GetMapping("/getConfig")
    public R<ConfigVO> getConfig(){
        ConfigVO configVO = sysUserService.getConfig();
        return R.success(configVO);
    }

    /**
     * 首页和全局数据
     *
     * @return {@link R}
     */
    @GetMapping("/index")
    public R index(){
        IndexVO indexVO = indexService.index();
        return R.success(indexVO);
    }

    /**
     * 文章详情数据
     *
     * @return {@link R}
     */
    @GetMapping("/show")
    public R show(Long id){
        ArticleShowVO articleShowVO = indexService.show(id);
        return R.success(articleShowVO);
    }

    /**
     * 文章列表数据
     *
     * @return {@link R}
     */
    @GetMapping("/list")
    public R<PageInfoVO<YddArticleVO2>> list(Integer page,Integer limit, Integer cateid){
        PageInfoVO<YddArticleVO2> list = indexService.list(page,limit,cateid);
        return R.success(list);
    }

    /**
     * 推荐文章---ishot = 1,istop = 1
     *
     * @return {@link R}
     */
    @GetMapping("/recommend")
    public R recommend(){
        RecommendVO recommendVO = indexService.recommend();
        return R.success(recommendVO);
    }

    /**
     * 最新文章
     *
     * @return
     */
    @GetMapping("/hot")
    public R hot(){
        RecommendVO hotVO = indexService.hot();
        return R.success(hotVO);
    }

    /**
     * 热门置顶文章数据(首页)
     *
     * @return {@link R}
     */
    @GetMapping("/new")
    public R<HotAndTopVO> hotAndTop(Integer page,Integer limit){
        HotAndTopVO hotAndTopVO = indexService.hotAndTop(page,limit);
        return R.success(hotAndTopVO);
    }

}
